using UnityEngine;
using System.Collections;

public class MoveMenu : MonoBehaviour {
	
	float moveThisMuch = 17;
	Vector3 moveVector;
	Vector3 targetPosition;
	
	public float animationSpeed = 1.0f;
	float animationPosition = 0;
	bool animationRunning = false;
	
	private int swipePosition = 0;
	private int swipesAllowed = 0;
	
	void Start() {
		
		moveVector = new Vector3(moveThisMuch,0,0);
		targetPosition = transform.position;
	}
	
	void Update() {
		
		// Move object menu to desired position
		
		transform.position = Vector3.Lerp(transform.position, targetPosition, animationPosition);
		animationPosition += Time.deltaTime * animationSpeed;
		
		// If moving has finished allow another swipe
		
		if (transform.position.Equals(targetPosition)) {
			animationRunning = false;
			animationPosition = 0;
		}
	}
	
	void SwipeLeft() {
		
		if (swipePosition > 0 && !animationRunning) {
			animationRunning = true;
			targetPosition = transform.position + moveVector;
			--swipePosition;
		}	
	}
	
	void SwipeRight() {
	
		if (swipePosition < swipesAllowed && !animationRunning) {
			animationRunning = true;
			targetPosition = transform.position - moveVector;
			++swipePosition;
		}
	}
	
	// Cannot swipe past the grid
	void SetSwipesAllowed(int amount) {
		swipesAllowed = amount;
	}
}